package contracts.simpleCodingQuiz

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method("GET")
        url(value(producer("/api/simpleCodingQuizzes/1")
                , consumer(regex("/api/simpleCodingQuizzes/\\d+")))) {
            queryParameters {
                parameter("status", "")
            }
        }
    }
    response {
        status(200)
        body("""
        {
            "id": 1,
            "definitionRepo": "https://github.com/Aceysx/java-collection-operator.git",
            "description": "sss",
            "evaluateScript": "1542019086473-bee0d2ed-e615-410e-97b7-06d84e3529e8.sh",
            "homeworkName": "测试用的题目",
            "jobMessage": "正在初始化,↵正在 clone 仓库,↵检测到无answer分支，将不会创建答案。↵开始检测测试脚本，↵检测到测试脚本，正在创建测试脚本,↵创建测试脚本成功。↵正在生成模版仓库，↵新建模版仓库地址是 github.com/recruiting-system/java-collection-operator-2018-11-12-10-37-55-147.git。↵出题成功↵",
            "makerId": 5,
            "quizGroupId": 2,
            "stackId": 4,
            "status": 1,
            "templateRepository": "https://github.com/recruiting-system/java-collection-operator-2018-11-12-10-37-55-147.git"
        }
        """)
        bodyMatchers {
            jsonPath('$', byType())
            jsonPath('$.id', byRegex(number()))
            jsonPath('$.description', byRegex("[\\s\\S]+"))
            jsonPath('$.evaluateScript', byRegex("[\\s\\S]+"))
            jsonPath('$.templateRepository', byRegex("[\\s\\S]+"))
            jsonPath('$.makerId', byRegex(number()))
            jsonPath('$.stackId', byRegex(number()))
            jsonPath('$.definitionRepo', byRegex("[\\s\\S]+"))
            jsonPath('$.status', byRegex(number()))
            jsonPath('$.quizGroupId', byRegex(number()))
        }
        headers {
            contentType(applicationJsonUtf8())
        }
    }
}
